import requests
import time
from bs4 import BeautifulSoup


def get_weibo_hot():
    url = "https://s.weibo.com/top/summary?cate=realtimehot"
    headers = {
        "Cookie": "SUB=_2AkMT0zixf8NxqwJRmP4RzG3iaIxxyQnEilj8lqJRMxHRl-yT9kqm0dtRB6OFMWXlM5SjftExkMQK6NASTHqZWXWFEB;"}
    resp = requests.get(url=url, headers=headers)
    resp.encoding = 'utf-8'
    html = resp.text
    soup = BeautifulSoup(html, 'html.parser')
    news = soup.findAll(class_='td-02')
    news.reverse()
    base_url = "https://s.weibo.com"
    news_ls = []
    i = 0
    for new in news:
        i = i + 1
        url = base_url + new.find('a').attrs['href']
        # print(url)
        title = new.find('a').text
        # print(('\033[1;37m' + str(i) + '\033[0m').center(50, '*'))
        # print('\033[1;36m' + title + '\033[0m')
        news_ls.append({"title": title, "url": url})
    return news_ls
